#include <bits/stdc++.h>
using namespace std;
int t,n,m,l,v,d[200000],u[200000],a[200000],p[200000],v1,v2,q,k,ans,cnt,anss,b[200000],f,c[200000],cntt,y,x,r[200000],pp,ppp,pppp;
vector<int> viss[200000];
vector<int> vis[200000];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        for(int i=0;i<m;i++) vis[i].clear();
        memset(r,0,sizeof(r));
        cin>>n>>m>>l>>v;
        for(int i=0;i<n;i++) {
                cin>>d[i]>>u[i]>>a[i];
                if(a[i]!=0) pppp=1;
        }
        for(int i=0;i<m;i++) cin>>p[i];
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        for(int i=0;i<m;i++) viss[i].clear();
        if(pppp!=1){
            for(int i=0;i<n;i++){
                if(u[i]>v) ans++;
            }
            if(ans==0) cout<<0<<" "<<m<<endl;
            else cout<<ans<<" "<<m-1<<endl;
        }
        else{
            for(int i=0;i<n;i++){
                q=0;
                v2=100002;
                k=0;
                for(int j=0;j<m;j++){
                    if(p[j]<d[i]) continue;
                    double z=sqrt(u[i]*u[i]+2*a[i]*(p[j]-d[i]));
                    //cout<<z<<" ";
                    if(z>v and k==0) {
                        v1=i;
                        v2=j;
                        k=1;
                    }
                    //cout<<u[i]*u[i]+2*a[i]*(p[j]-d[i])<<" ";
                    if(u[i]*u[i]+2*a[i]*(p[j]-d[i])<=0 and k!=0){
                        vis[j-1].push_back(2);
                        b[j-1]=1;
                        q++;
                        ans++;
                        pp++;
                        //cout<<1<<" "<<v2<<" "<<i<<" "<<b[v2]<<endl;
                        //cout<<i<<" ";
                        for(int w=v2;w<j;w++) viss[w].push_back(i);
                        break;
                    }
                }
                //cout<<endl;
                if(k!=0 and q==0) {
                    vis[v2].push_back(1);
                    ans++;
                    //cout<<i<<" ";
                }
            }
            //for(int i=0;i<m;i++)cout<<b[i]<<" ";
            while(1){
                y=0;
                for(int i=0;i<m;i++){
                    cntt=0;
                    for(int j=0;j<viss[i].size();j++){
                        if(c[viss[i][j]]==0) cntt++;
                    }
                    if(cntt>y) {
                        y=cntt;
                        x=i;
                    }
                }
                f++;
                r[x]=1;
                for(int i=0;i<viss[x].size();i++){
                    if(c[viss[x][i]]!=1){
                        c[viss[x][i]]=1;
                        ppp++;
                    }
                }
                if(ppp>=pp) break;

            }
            for(int i=0;i<m;i++){
                if(r[i]==1){
                        //cout<<i<<" ";
                    cnt=0;
                }
                else cnt+=vis[i].size();
            }
            if(cnt>0) f++;
            cout<<ans<<" "<<m-f<<endl;
            ans=0;
            f=0;
        }
    }
    return 0;
}
